/**
 * Created by Will Bean on 2016/4/25.
 */
import React, { Component,PropTypes } from 'react'

class TextareaInput extends Component{
    constructor(props){
        super(props);

        this.state = {message: this.props.val }; // 初始化状态
    }

	componentWillReceiveProps(nextProps){//除手动输入之外的方式改变val
		if(nextProps.val){
			this.setState({
				message : nextProps.val
			})
		}
	}
	
    handleChange(e){
        var m = e.target.value;
        this.setState({message: m});
        this.props.onChange(m)
    }

    render(){
        const { name, id, style, textareaClass} = this.props;
        var message = this.state.message;
        return(
            <textarea disabled={this.props.disabled} name={name} id={id} style={style} className={textareaClass} value={message} onChange={this.handleChange.bind(this)}/>
        )
    }
}

TextareaInput.propTypes = {
    onChange: PropTypes.func.isRequired,
    val : PropTypes.string.isRequired
};

export default TextareaInput;